package com.mooc.lib_common.model

import android.os.Parcel
import android.os.Parcelable

/**
 * 作者实体类:
 * Parcelable
 * Serializable
 * 异同:相同点:都可以做对象序列化->Intent对象传递
 *      区别:1.Serializable->JavaApi，Parcelable->Android提供
 *           2.Serializable频繁的io本地读取操作,Parcelable依托于内存不会产生磁盘操作
 * */
class AuthorEntity() : Parcelable{

    var id = 0L
    var userId = 0L
    var name = ""
    var avatar = ""
    var description = ""
    var likeCount = 0
    var topCommentCount = 0
    var followCount = 0
    var followerCount = 0
    var qqOpenId = ""
    var expires_time = 0L
    var score = 0
    var historyCount = 0
    var commentCount = 0
    var favoriteCount = 0
    var feedCount = 0
    var hasFollow = false
    var ugc : UGCEntity ?= null

    constructor(parcel: Parcel) : this() {
        id = parcel.readLong()
        userId = parcel.readLong()
        name = parcel.readString()!!
        avatar = parcel.readString()!!
        description = parcel.readString()!!
        likeCount = parcel.readInt()
        topCommentCount = parcel.readInt()
        followCount = parcel.readInt()
        followerCount = parcel.readInt()
        qqOpenId = parcel.readString()!!
        expires_time = parcel.readLong()
        score = parcel.readInt()
        historyCount = parcel.readInt()
        commentCount = parcel.readInt()
        favoriteCount = parcel.readInt()
        feedCount = parcel.readInt()
        hasFollow = parcel.readByte() != 0.toByte()
        ugc = parcel.readParcelable(UGCEntity::class.java.classLoader)
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeLong(id)
        parcel.writeLong(userId)
        parcel.writeString(name)
        parcel.writeString(avatar)
        parcel.writeString(description)
        parcel.writeInt(likeCount)
        parcel.writeInt(topCommentCount)
        parcel.writeInt(followCount)
        parcel.writeInt(followerCount)
        parcel.writeString(qqOpenId)
        parcel.writeLong(expires_time)
        parcel.writeInt(score)
        parcel.writeInt(historyCount)
        parcel.writeInt(commentCount)
        parcel.writeInt(favoriteCount)
        parcel.writeInt(feedCount)
        parcel.writeByte(if (hasFollow) 1 else 0)
        parcel.writeParcelable(ugc, flags)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<AuthorEntity> {
        override fun createFromParcel(parcel: Parcel): AuthorEntity {
            return AuthorEntity(parcel)
        }

        override fun newArray(size: Int): Array<AuthorEntity?> {
            return arrayOfNulls(size)
        }
    }
}